package bdz.playground.points
{
	import bdz.common.utils.MathUtils;
	import bdz.common.utils.Vector2D;
	import bdz.playground.core.PenPoint;

	public class SteeringPoint extends PenPoint {
		
		public var maxForce:Number = 1;
		public var steeringForce:Vector2D;
		
		public function SteeringPoint() {
			steeringForce = new Vector2D();
			super();
		}
		override protected function render():void{
			if(follow){
				seek(follow);
			}
			steeringForce.truncate(maxForce);
			steeringForce = steeringForce.divide(mass);
			velocity = velocity.add(steeringForce);
			steeringForce = new Vector2D();
			steer();
		}
		protected function steer():void{
			velocity.truncate(maxSpeed);
			_position = _position.add(velocity);
			rotation = MathUtils.radianToDegree(velocity.angle);
		}
		public function seek(target:Vector2D):void{
			var targetVelocity:Vector2D = target.subtract(_position);
			targetVelocity.normalize();
			targetVelocity = targetVelocity.multiply(maxSpeed);
			var force:Vector2D = targetVelocity.subtract(velocity);
			steeringForce = steeringForce.add(force);
			
		}
	}
}